package com.ibp.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/****
 * @author yf141
 * 统计各方法耗时切面
 */
@Aspect
@Component
public class StatisticalConsumeTimeAspect {

	private static final Logger logger = LoggerFactory.getLogger(StatisticalConsumeTimeAspect.class);
	                       
	@Pointcut("execution(* com.ibp.service.*.*(..))")
	public void inAnyMethod(){
		
	}
	
	//声明环绕通知
	@Around("inAnyMethod()")
	public Object doAround(ProceedingJoinPoint pjp) throws Throwable{
		long beginTime = System.currentTimeMillis();
			Object obj = pjp.proceed();
		long endTime = System.currentTimeMillis() ;
		logger.info("{}:{}", pjp.getArgs().getClass()+"."+pjp.getSignature(), "耗时："+(endTime-beginTime)+"ms");
		return obj;
        		
	}
	
}
